[Node.js] Align Public APIs across SDKs#221
Conversation
BREAKING CHANGE: InvokeAgentDetails uses composition (details: AgentDetails) instead of inheritance (extends AgentDetails). - InvokeAgentScope.start() adds request and conversationId as separate params - Removed providerName and agentBlueprintId from InvokeAgentDetails - Added OpenTelemetryScope.setStartTime() and recordCancellation() - Added OpenTelemetryConstants.ERROR_TYPE_CANCELLED constant
There was a problem hiding this comment.
Pull request overview
Aligns the Node.js observability SDK’s InvokeAgentDetails and InvokeAgentScope.start() API shape/signature with the .NET and Python SDKs, while adding a couple of core scope utilities for timing and cancellation telemetry.
Changes:
- Refactors
InvokeAgentDetailsfrom inheritance to composition ({ details: AgentDetails }) and updatesInvokeAgentScope.start()signature to acceptrequestandconversationIdexplicitly. - Adds
OpenTelemetryScope.setStartTime()andOpenTelemetryScope.recordCancellation(), plus a new cancellation error-type constant. - Updates hosting utilities and test suites to the new API shapes/signatures.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/observability/extension/hosting/scope-utils.test.ts | Updates hosting utility tests for composed InvokeAgentDetails and new InvokeAgentScope.start() signature. |
| tests/observability/core/trace-context-propagation.test.ts | Updates trace-context propagation tests to match the new start() parameter order. |
| tests/observability/core/scopes.test.ts | Updates InvokeAgentScope tests for composed details; adds tests for conversationId precedence, request.channel tags, setStartTime, and recordCancellation. |
| tests/observability/core/parent-span-ref.test.ts | Updates parent-span reference tests for composed details and new start() signature. |
| packages/agents-a365-observability/src/tracing/scopes/OpenTelemetryScope.ts | Adds setStartTime() and recordCancellation(); adjusts duration logging; changes setTagMaybe visibility. |
| packages/agents-a365-observability/src/tracing/scopes/InvokeAgentScope.ts | Implements new start() signature, derives channel tags from request.channel, and uses composed agent identity. |
| packages/agents-a365-observability/src/tracing/contracts.ts | Updates InvokeAgentDetails to composition model and removes legacy header. |
| packages/agents-a365-observability/src/tracing/context/trace-context-propagation.ts | Updates docs/examples for new InvokeAgentScope.start() signature. |
| packages/agents-a365-observability/src/tracing/constants.ts | Adds OpenTelemetryConstants.ERROR_TYPE_CANCELLED. |
| packages/agents-a365-observability-hosting/src/utils/ScopeUtils.ts | Adapts hosting scope population to build/pass request separately and merge identity into details.details. |
| CHANGELOG.md | Documents breaking changes and new APIs introduced by this alignment work. |
You can also share your feedback on Copilot code review. Take the survey.
packages/agents-a365-observability/src/tracing/scopes/OpenTelemetryScope.ts
Outdated
Show resolved
Hide resolved
packages/agents-a365-observability-hosting/src/utils/ScopeUtils.ts
Outdated
Show resolved
Hide resolved
packages/agents-a365-observability/src/tracing/scopes/InvokeAgentScope.ts
Outdated
Show resolved
Hide resolved
- Revert setTagMaybe from public back to protected (Copilot comment #1) - Only build request object when channel/conversationId data exists in ScopeUtils populate* methods, avoiding always-truthy empty channel objects (Copilot comment #2) - Update all 5 failing test suites to match new scope API signatures: scopes.test.ts, output-scope.test.ts, parent-span-ref.test.ts, trace-context-propagation.test.ts, scope-utils.test.ts Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Include all modified source files that were missing from the previous commit: new scope signatures, contracts, exports, CHANGELOG, and hosting middleware updates. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Aligns the Node.js observability SDK public APIs with the .NET/Python SDKs by replacing long positional scope start() signatures with typed request/details objects, and consolidating span options into a single SpanDetails object.
Changes:
- Refactors scope construction APIs (
InvokeAgentScope,InferenceScope,ExecuteToolScope,OutputScope) to use request/details objects and derive tenant ID fromAgentDetails.tenantId. - Renames W3C trace-context helpers to
injectContextToHeaders/extractContextFromHeadersand updates exports + tests accordingly. - Adds
SpanDetails,InvokeAgentCallerDetails, request context types,recordCancellation(), andObservabilityBuilder.withServiceNamespace(); updates hosting utilities and test suite.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/observability/extension/hosting/scope-utils.test.ts | Updates hosting ScopeUtils tests for new details/request object shapes and updated error messages. |
| tests/observability/core/trace-context-propagation.test.ts | Updates tests to use renamed context propagation helpers and new InvokeAgentScope.start() signature. |
| tests/observability/core/scopes.test.ts | Updates scope tests for new signatures; adds coverage for conversationId/channel tagging and cancellation recording. |
| tests/observability/core/parent-span-ref.test.ts | Updates parent-span tests for new SpanDetails.parentContext parameter pattern. |
| tests/observability/core/output-scope.test.ts | Updates OutputScope tests for new request/SpanDetails-based constructor signature. |
| packages/agents-a365-observability/src/tracing/scopes/OutputScope.ts | Switches OutputScope start signature to (request, response, agentDetails, ...) and derives tenantId from agentDetails. |
| packages/agents-a365-observability/src/tracing/scopes/OpenTelemetryScope.ts | Updates docs for renamed extract helper; adds recordCancellation(); tweaks end-span logging. |
| packages/agents-a365-observability/src/tracing/scopes/InvokeAgentScope.ts | Refactors InvokeAgentScope to composition-based InvokeAgentDetails.details and new caller/span option objects. |
| packages/agents-a365-observability/src/tracing/scopes/InferenceScope.ts | Refactors InferenceScope to accept InferenceRequest + SpanDetails and derives tenantId from agentDetails. |
| packages/agents-a365-observability/src/tracing/scopes/ExecuteToolScope.ts | Refactors ExecuteToolScope to accept ToolRequest + SpanDetails and derives tenantId from agentDetails. |
| packages/agents-a365-observability/src/tracing/contracts.ts | Introduces request context interfaces, InvokeAgentCallerDetails, and SpanDetails; changes InvokeAgentDetails to composition. |
| packages/agents-a365-observability/src/tracing/context/trace-context-propagation.ts | Renames inject/extract helpers; updates examples and runWithExtractedTraceContext() implementation. |
| packages/agents-a365-observability/src/tracing/constants.ts | Adds ERROR_TYPE_CANCELLED constant value. |
| packages/agents-a365-observability/src/index.ts | Re-exports renamed propagation helpers and newly added contract types. |
| packages/agents-a365-observability/src/ObservabilityBuilder.ts | Adds withServiceNamespace() and emits service.namespace resource attribute when configured. |
| packages/agents-a365-observability-hosting/src/utils/ScopeUtils.ts | Updates TurnContext-derived scope creation to build typed request objects and pass SpanDetails. |
| packages/agents-a365-observability-hosting/src/middleware/OutputLoggingMiddleware.ts | Updates OutputLoggingMiddleware to pass OutputRequest + SpanDetails into OutputScope. |
| CHANGELOG.md | Documents breaking API changes, additions, and renamed APIs. |
packages/agents-a365-observability-hosting/src/utils/ScopeUtils.ts
Outdated
Show resolved
Hide resolved
juliomenendez
left a comment
There was a problem hiding this comment.
There are several argument changes in this PR. Can we review how to make them backwards compatible to avoid breaking existing integrations?
Currently in preview phase. Discussed offline about the breaking changes. We will notify developers about the changes. |
packages/agents-a365-observability/src/tracing/scopes/InvokeAgentScope.ts
Outdated
Show resolved
Hide resolved
packages/agents-a365-observability/src/tracing/scopes/ExecuteToolScope.ts
Outdated
Show resolved
Hide resolved
packages/agents-a365-observability/src/tracing/scopes/OutputScope.ts
Outdated
Show resolved
Hide resolved
packages/agents-a365-observability/src/tracing/scopes/InvokeAgentScope.ts
Outdated
Show resolved
Hide resolved
- Rename AgentRequest → Request, use across all scopes (remove InferenceRequest, ToolRequest, OutputRequest) - Remove executionType from Request interface - Rename CallerDetails → UserDetails (human caller) - Rename InvokeAgentCallerDetails → CallerDetails (composite caller) with userDetails property instead of callerDetails - InvokeAgentScope.start: request param is now required (not undefined) - Remove caller derivation from agent details — caller is always human - Fix stale JSDoc on populateInvokeAgentScopeFromTurnContext - Update all tests for new type names Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- CHANGELOG: fix all stale type references (InvokeAgentCallerDetails → CallerDetails, InferenceRequest/ToolRequest/OutputRequest → Request, callerDetails → userDetails, AgentRequest → Request) - design.md: update code examples to use new scope signatures - design.md: fix InvokeAgentDetails to composition model - ScopeUtils: fix stale comment on request building Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
packages/agents-a365-observability/src/tracing/scopes/ExecuteToolScope.ts
Show resolved
Hide resolved
packages/agents-a365-observability/src/tracing/context/trace-context-propagation.ts
Outdated
Show resolved
Hide resolved
packages/agents-a365-observability-hosting/src/middleware/OutputLoggingMiddleware.ts
Show resolved
Hide resolved
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Make request: Request required (not | undefined) on InferenceScope,
ExecuteToolScope, and OutputScope to match InvokeAgentScope
- Rename callerInfo → callerDetails on InvokeAgentScope
- Fix JSDoc example in trace-context-propagation.ts
- Update ScopeUtils to always build Request objects
- Update all tests to pass {} instead of undefined for request
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
packages/agents-a365-observability-hosting/src/middleware/OutputLoggingMiddleware.ts
Outdated
Show resolved
Hide resolved
packages/agents-a365-observability/src/tracing/scopes/InvokeAgentScope.ts
Outdated
Show resolved
Hide resolved
- Move request param after required params so it can be truly optional (details, agentDetails, request?, userDetails?, spanDetails?) - Revert sessionId fallback — read only from invokeAgentDetails to match .NET/Python SDKs - Update CHANGELOG and design docs Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
packages/agents-a365-observability-hosting/src/middleware/OutputLoggingMiddleware.ts
Show resolved
Hide resolved
packages/agents-a365-observability/src/tracing/scopes/InvokeAgentScope.ts
Show resolved
Hide resolved
…ceNamespace test - Guard against undefined invokeAgentDetails.details before accessing tenantId - Add test for withServiceNamespace builder option (service.namespace resource attribute) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
packages/agents-a365-observability/src/tracing/scopes/InvokeAgentScope.ts
Show resolved
Hide resolved
packages/agents-a365-observability-hosting/src/utils/ScopeUtils.ts
Outdated
Show resolved
Hide resolved
db4052d to
20e8508
Compare
packages/agents-a365-observability/src/tracing/scopes/InvokeAgentScope.ts
Outdated
Show resolved
Hide resolved
packages/agents-a365-observability-hosting/src/middleware/OutputLoggingMiddleware.ts
Show resolved
Hide resolved
…ntDetails, move sessionId to Request
…Details to InvokeAgentScopeDetails Simplify contracts by removing single-field TenantDetails wrapper and absorbing tenantId directly into AgentDetails. Update all scope signatures, ScopeUtils helpers, docs, and tests accordingly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
packages/agents-a365-observability/src/tracing/scopes/InferenceScope.ts
Outdated
Show resolved
Hide resolved
packages/agents-a365-observability/src/tracing/scopes/ExecuteToolScope.ts
Outdated
Show resolved
Hide resolved
packages/agents-a365-observability/src/tracing/scopes/InvokeAgentScope.ts
Outdated
Show resolved
Hide resolved
packages/agents-a365-observability/src/tracing/scopes/OutputScope.ts
Outdated
Show resolved
Hide resolved
# Conflicts: # CHANGELOG.md # packages/agents-a365-observability-hosting/src/utils/ScopeUtils.ts # packages/agents-a365-observability/src/tracing/scopes/InvokeAgentScope.ts # packages/agents-a365-observability/src/tracing/scopes/OpenTelemetryScope.ts # tests/observability/core/scopes.test.ts
…ix stale docs - Remove tenantDetails param from OpenTelemetryScope constructor; tenant ID now read directly from agentDetails.tenantId - Remove redundant tenantDetails local variable from all 4 scope subclasses - Remove duplicate operationName tag in InferenceScope (already set by base) - Remove inconsistent request null-check from OutputScope (align with other scopes) - Remove unused imports (ExecutionType, InvokeAgentScopeDetails, TenantDetails) - Fix stale property names in design docs (callerId→userId, callerUpn→userEmail) - Fix duplicate SourceMetadata changelog entry Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
Aligns the Node.js observability SDK public APIs with the .NET and Python SDKs by restructuring scope method signatures to use typed request/details objects instead of long positional parameter lists.
Breaking Changes (
@microsoft/agents-a365-observability)InvokeAgentDetailsrenamed toInvokeAgentScopeDetails— now contains only scope-level config (endpoint). Agent identity (AgentDetails) is a separate parameter.sessionIdmoved toRequest.InvokeAgentScope.start(): New signaturestart(request, invokeScopeDetails, agentDetails, callerDetails?, spanDetails?).requestis required. Tenant ID derived fromagentDetails.tenantId. Caller info wrapped inCallerDetails.InferenceScope.start(): New signaturestart(request, details, agentDetails, userDetails?, spanDetails?).requestis required. Tenant ID derived fromagentDetails.tenantId.ExecuteToolScope.start(): New signaturestart(request, details, agentDetails, userDetails?, spanDetails?). Same pattern as InferenceScope.OutputScope.start(): New signaturestart(request, agentDetails, userDetails?, spanDetails?). Same pattern.AgentRequestrenamed toRequest— unified across all scopes. RemovedInferenceRequest,ToolRequest,OutputRequest. RemovedexecutionTypefield.CallerDetailsrenamed toUserDetails— represents the human caller identity.InvokeAgentCallerDetailsrenamed toCallerDetails— composite caller withuserDetailsandcallerAgentDetails.TenantDetailsremoved —tenantIdabsorbed directly intoAgentDetails.tenantDetailsparameter removed from all scopestart()methods. Tenant ID now required onAgentDetails.tenantId.injectTraceContext()renamed toinjectContextToHeaders().extractTraceContext()renamed toextractContextFromHeaders().setStartTime()removed — useSpanDetails.startTimeon construction instead.UserDetailsis always the human caller, not derived fromcallerAgentDetails.Added
SpanDetails— groupsparentContext,startTime,endTime,spanKindfor scope construction.CallerDetails— groupsuserDetailsandcallerAgentDetailsfor A2A scenarios.Request— unified request context withconversationId,channel,content,sessionId.OpenTelemetryScope.recordCancellation()— records cancellation witherror.type = 'TaskCanceledException'.OpenTelemetryConstants.ERROR_TYPE_CANCELLEDconstant.🤖 Generated with Claude Code